package com.certification.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.certification.common.utils.Constant;
import com.certification.entity.Certification;
import com.certification.service.CertificationService;
import com.certification.service.SysUserRoleService;
import com.certification.vo.PageVO;
import com.certification.vo.ResponseMessage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import java.util.List;

import static com.certification.constants.CertConstant.CERTIFICATION;

/**
 * @author copa
 * @createDate 2022-03-28 21:55
 * @function 流程：认证申请
 */
@RestController
@Api(tags = {"流程：认证申请"})
public class CertificationController extends AbstractController{

    @Resource
    private CertificationService certificationService;

    @Resource
    private SysUserRoleService sysUserRoleService;

    @GetMapping("admin/certlist")
    @ApiOperation(value = "查看认证列表（认证专家）")
    public ResponseMessage<Page<Certification>> certList(PageVO pageVO) {
        for (Long roleId : sysUserRoleService.queryRoleIdList(getUser().getUserId())) {
            if (roleId == Constant.ROLE_EXPERT) {
                //return certificationService.certList();
                return certificationService.certListPage(pageVO);
            }
        }
        return ResponseMessage.errorMsg("该角色不能调用该接口~");
    }

    @GetMapping("admin/certDetail/{certId}")
    @ApiOperation(value = "查看详细认证（认证专家）")
    public ResponseMessage<Certification> getCertDetailAdmin(@PathVariable Integer certId) {
        return certificationService.getCertDetailAdmin(certId);
    }

    @GetMapping("admin/certDetailPage/{certId}")
    @ApiOperation(value = "查看详细认证分页（认证专家）")
    public ResponseMessage<Page<Certification>> getCertDetailAdminPage(@PathVariable Integer certId, PageVO pageVO) {
        return certificationService.getCertDetailAdminPage(certId, pageVO);
    }

    @PutMapping("admin/cert")
    @ApiOperation(value = "判定认证是否通过：第一阶段")
    public ResponseMessage<String> putCertAdmin(@RequestParam @ApiParam("认证id") Integer certId,
                                  @RequestParam @ApiParam("同意-1 驳回-2") Integer status,
                                  @RequestParam(required = false) @ApiParam("驳回和同意写理由") String remark) {
        return certificationService.putCertAdmin(certId, status, remark, CERTIFICATION);
    }
}
